﻿<div class="ph-tabs">
    <ul>
        <li class="k-state-active">学生信息</li>
        <li>批量导入学生</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <div style="display: inline-block;">
                <select id="selClass"></select>
            </div>
            <span class="k-textbox k-space-right">
                <input type="text" placeholder="请输入学生名称" id="txtKey" />
                <a href="javascript:FilterStudent()" class="k-icon k-i-search">&nbsp;</a>
            </span>
            <button class="k-button" onclick="CreateNewStudent()"><span class="k-icon k-i-plus"></span><span>添加新学生</span></button>
            <button class="k-button" onclick="DeleteStudents()"><span class="k-icon k-i-close"></span><span>删除学生</span></button>
            <a class="k-button" onclick="Export()"><span class="k-icon k-i-calendar"></span><span>导出学生</span></a>
        </div>
        <div id="grid_student" style="text-align: center"></div>
    </div>
    <div>
        <div class="GeneralEdit" id="fmStudentImport">
            <ul>
                <li>
                    <label>模板：</label>
                    <a href="/RootFiles/Templates/template_student.xls" target="_blank" class="k-button">点击下载学生信息导入模板</a>
                </li>
                <li>
                    <label>学校编码：</label>
                    <a href="/School/SchoolInfo/ExportSchoolCode/1" target="_blank" class="k-button">点击下载学校编码表</a>
                </li>
                <li>
                    <label>上传文件：</label>
                    <ul class="upfile k-block">
                        <li>
                            <input type="file" id="fileAux" name="fileAux" data-fid="" /></li>
                        <li>
                            <h4 id="fuAuxMsg"></h4>
                        </li>
                    </ul>
                </li>
                <li id="lip">
                    <label>完成进度：</label>
                    <div id="progressbar"></div>
                </li>

                <li class="editButtons">
                    <button id="btnImport" class="k-button"><span class="k-icon k-i-tick"></span><span>开始导入</span></button>
                </li>
            </ul>
        </div>
    </div>
    <form id="exportForm" method="post" action="/School/Student/Export" target="_blank" style="display: none">
        <input type="hidden" name="classGuid" id="df_ClassGuid" />
        <input type="hidden" name="key" id="df_Key" />
    </form>
</div>

<script class="init">
    LocatedMenu("学校管理", "学生管理");

    $("#selClass").kendoDropDownList({
        optionLabel: {
            ClassName: "请选择班级...",
            ID: ""
        },
        dataTextField: "ClassName",
        dataValueField: "Guid",
        dataSource: Whale.dataSource({
            url: "/School/Class/GetClasses",
            getParameters: function () {
                return { schoolGuid: "@PH.Web.Global.WebContext.CurrentSchool.Guid" }
            }
        }),
        change: function (e) {
            FilterStudent();
        }
    });

    function Export() {
        $("#df_ClassGuid").val($("#selClass").data("kendoDropDownList").value());
        $("#df_Key").val($.trim($("#txtKey").val()));
        $("#exportForm").submit();
    }
    var pb = $("#progressbar").kendoProgressBar({
        type: "percent",
        min: 0,
        max: 100
    }).data("kendoProgressBar");
    $("#lip").hide();
</script>

<script class="grid_student_columns">
    var studentFields = [{
        title: "<input type='checkbox' onclick='SelectAll()' />",
        template: "#=CheckBox(Guid)#",
        width: 50
    }, {
        title: "身份证",
        field: "StudentNo",
        width: 150
    }, {
        title: "学生姓名",
        field: "RealName",
        width: 150
    }, {
        title: "性别",
        field: "Sex",
        template: "#=Sex==1?'男':'女'#",
        width: 60
    }, {
        title: "所在班级",
        field: "ClassName",
        width: 150
    }, {
        title: "联系手机",
        field: "Mobile",
        width: 100
    }, {
        title: "添加时间",
        template: "#=kendo.toString(kendo.parseDate(CreatedOn),'yyyy-MM-dd')#",
        width: 100
    }, {
        title: "操作",
        template: "#=GetOperations(Guid)#",
        attributes: { style: "text-align:left" }
    }];

    function GetOperations(guid) {
        var html = "<button class='k-button' onclick=\"EditStudent('" + guid + "')\"><span class='k-icon k-i-pencil'></span><span>修改</span></button>";
        html += "<button class='k-button' onclick=\"DeleteStudent('" + guid + "')\"><span class='k-icon k-i-close'></span><span>删除</span></button>";
        //html += "<button class='k-button' onclick=\"StudentMark('" + guid + "')\"><span class='k-icon k-i-calendar'></span><span>成绩</span></button>";
        return html;
    }

    function EditStudent(guid) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "修改学生信息" });
            wndGeneralEdit.refresh({ url: "/School/Student/Edit/@ViewBag.SchoolGuid/" + guid });
            wndGeneralEdit.open();
        }
    }

    function DeleteStudent(guid) {
        if (confirm("真的要删除这个学生吗？")) {
            Whale.Remote.Operation({
                url: "/School/Student/DeleteStudent",
                parameters: { guid: guid },
                success: function (result) {
                    FilterStudent();
                },
                error: function (msg) {
                    wndGeneralInformation.content(msg).open();
                }
            });
        }
    }

    function CheckBox(orderNo) {
        var html = "<input type='checkbox' data-value='" + orderNo + "' />";
        return html;
    }

    function SelectAll() {
        var obj = $("#grid_student table tr th input[type='checkbox']")
        $("#grid_student table td input[type='checkbox']").prop("checked", obj.is(":checked"));
    }

    function StudentMark(guid) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "查看学生成绩记录", width: 1000 });
            wndGeneralEdit.refresh({ url: "/Statistics/StudentScore/History/" + guid });
            wndGeneralEdit.open();
        }
    }

</script>

<script class="grid_config">
    $(function () {
        $("#grid_student").kendoGrid({
            columns: studentFields,
            dataSource: Whale.dataSource({
                url: "/School/Student/GetStudents",
                getParameters: function () {
                    return {
                        schoolGuid: "@PH.Web.Global.WebContext.CurrentSchool.Guid",
                        key: $.trim($("#txtKey").val()),
                        classGuid: $("#selClass").data("kendoDropDownList").value()
                    };
                },
                pageSize: 20

            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            }
        });
    });
</script>

<script class="fn">
    function CreateNewStudent() {
        wndGeneralEdit.setOptions({ title: "添加新的学生" });
        wndGeneralEdit.refresh({ url: "/School/Student/Edit/@ViewBag.SchoolGuid" });
        wndGeneralEdit.open();
    }

    function FilterStudent() {
        $("#grid_student").data("kendoGrid").dataSource.page(0);
    }

    function DeleteStudents() {
        if (confirm("真的要删除这些学生吗？")) {
            var guids = "";
            var c = 1;
            $("#grid_student table td input:checked").each(function (i, o) {
                guids += "," + $(o).attr("data-value");
                c++;
            });

            if (guids.length > 0) {
                guids = guids.substr(1);
                Whale.Remote.Operation({
                    url: "/School/Student/DelStudents",
                    parameters: { guids: guids },
                    success: function (result) {
                        wndGeneralInformation.content("共选择了" + c + "个学生，成功" + result + "个，失败" + (c - result) + "个。").open();
                        FilterStudent();
                    },
                    error: function (msg) {
                        wndGeneralInformation.content(msg).open();
                    }
                });
            } else
                wndGeneralInformation.content("请选择要删除的学生").open();
        }
    }
</script>

<script class="import_student">
    $(function () {
        $("#btnImport").click(function (e) {
            var values = {
                fGuid: $("#fileAux").attr("data-fid"),
                sGuid: "@ViewBag.SchoolGuid",
            };

            Whale.Remote.Operation({
                url: "/School/Student/ImportStudent",
                parameters: values,
                success: function (result) {
                    FilterStudent();
                    $(".ph-tabs").data("kendoTabStrip").select(0);
                },
                error: function (msg) {
                    wndGeneralInformation.content(msg).open();
                    FilterStudent();
                }
            });

            $("#btnImport").hide();
            $("#lip").show();
            setTimeout(function () {
                GetFileProgress(values.fGuid, pb);
            }, 3000);
        });
    });
</script>
